package se.chalmers.tda366.crumble.gui.dialogs;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import se.chalmers.tda366.crumble.core.ICategory;
import se.chalmers.tda366.crumble.gui.utils.CloseActionListener;
import se.chalmers.tda366.crumble.gui.utils.GuiObserv;
import se.chalmers.tda366.crumble.resources.Constants;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RemoveCategoryView extends JPanel {
	private JComboBox categoriesComboBox;
	private JLabel categoryRemoveHeadlineLabel;
	private JLabel warningMessage;
	private JButton categoryCancelButton;
	private JButton categoryRemoveButton;
	private JLabel removeLabel;
	private List<ICategory> categories;
	
	public RemoveCategoryView(List<ICategory> list){
		categories=list;
		initGUI();
		initCtrl();
	}

	private void initCtrl() {
		categoryCancelButton.addActionListener(new CloseActionListener());
		categoryRemoveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(((JButton)evt.getSource()).getParent(), Constants.Actions.REMOVE_CATEGORY);
			}
		});
	}
	
	public ICategory getCategory(){
		return (ICategory) categoriesComboBox.getSelectedItem();
	}

	private void initGUI() {
		try {
			{
				this.setPreferredSize(new Dimension(350, 150));
				this.setLayout(null);
				{
					ComboBoxModel categoriesComboBoxModel = 
						new DefaultComboBoxModel(categories.toArray());
					categoriesComboBox = new JComboBox();
					this.add(categoriesComboBox);
					categoriesComboBox.setModel(categoriesComboBoxModel);
					categoriesComboBox.setBounds(196, 59, 116, 25);
				}
				{
					removeLabel = new JLabel();
					this.add(removeLabel);
					removeLabel.setText("Select Category to Remove:");
					removeLabel.setBounds(33, 64, 157, 15);
				}
				{
					categoryRemoveHeadlineLabel = new JLabel();
					this.add(categoryRemoveHeadlineLabel);
					categoryRemoveHeadlineLabel.setText("Remove Category...");
					categoryRemoveHeadlineLabel.setBounds(33, 21, 279, 15);
					categoryRemoveHeadlineLabel.setFont(se.chalmers.tda366.crumble.resources.Constants.HEADLINEFONT);
				}
				{
					categoryRemoveButton = new JButton();
					this.add(categoryRemoveButton);
					categoryRemoveButton.setText("Remove");
					categoryRemoveButton.setBounds(237, 96, 75, 30);
				}
				{
					categoryCancelButton = new JButton();
					this.add(categoryCancelButton);
					categoryCancelButton.setText("Cancel");
					categoryCancelButton.setBounds(159, 96, 67, 30);
				}
				{
					warningMessage = new JLabel();
					this.add(warningMessage);
					warningMessage.setText("Removing a category will also remove all of its feeds");
					warningMessage.setBounds(33, 42, 308, 15);
					warningMessage.setForeground(new java.awt.Color(181,14,0));
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}
